package com.myapp.ruyixing.http;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

import com.myapp.ruyixing.model.MyReviewList;
import com.myapp.ruyixing.model.MyReviewList.Review;

public class MyReviewListParser extends RYJSONParser {
	@Override
	public Object parse(JSONObject jsonObject) {
		MyReviewList list = new MyReviewList();

		ListModelParser.parseListModel(list, jsonObject);
		JSONObject data = jsonObject.optJSONObject("data");
		JSONArray array = data.optJSONArray("items");
		list.items = new ArrayList<Review>();
		for (int i = 0; array != null && i < array.length(); i++) {
			JSONObject object = array.optJSONObject(i);
			if (object != null) {
				Review item = new Review();
				item.content = object.optString("content", "");
				item.score = object.optInt("score", 0);
				item.price = object.optString("price", "");
				item.datetime = object.optString("datetime", "");
				item.shopname = object.optString("shopname", "");
				item.shopid = object.optString("shopid", "");
				item.type = object.optString("type", "shop");
				item.username = object.optString("username", "");
				list.items.add(item);
			}
		}

		return list;

	}
}
